#ifndef _LISTPARSER_H_
#define _LISTPARSER_H_

#include "parser.h"
#include "common.h"

class ListParser : public Parser {
public:
    ListParser(ListLexer *input): Parser(input) { }

    void list() {
        match(LBRACK);
        elements();
        match(RBRACK);
    }

    void elements() {
        element();
        while (lookahead->type == COMMA) {
            match(COMMA);
            element();
        }
    }

    void element() {
        if (lookahead->type == NAME)
            match(NAME);
        else if (lookahead->type == LBRACK)
            list();
        else {
            string s = "expecting name or list; found ";
            s += lookahead->text;
            throw Error(s);
        }
    }
};

#endif
